package com.klb.action.catalog;

import com.klb.model.BbsArticle;
import com.klb.service.catalog.impl.IndexServiceCatalogImpl;
import com.klb.tools.Sessions;
import com.opensymphony.xwork2.ActionSupport;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by fujia on 2016/6/6.
 */
public class IndexActionCatalog extends ActionSupport {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private HashMap<String,Object> data;
	
	private IndexServiceCatalogImpl indexServiceCatalog;


	public void setIndexServiceCatalog(IndexServiceCatalogImpl indexServiceCatalog) {
		this.indexServiceCatalog = indexServiceCatalog;
	}
	

	@Override
    public String execute() throws Exception {
        List<BbsArticle> newArticles = this.indexServiceCatalog.getNewArticles();
        List<BbsArticle> hotArticles = this.indexServiceCatalog.getHotArticles();

        Sessions.setSession("newArticles", newArticles);
        Sessions.setSession("hotArticles", hotArticles);

        return SUCCESS;
    }

    public String jsonForIndex(){
        List<BbsArticle> newArticles = this.indexServiceCatalog.getNewArticles();
        List<BbsArticle> hotArticles = this.indexServiceCatalog.getHotArticles();

        this.data = new HashMap<>();

        this.data.put("newArticles", newArticles);
        this.data.put("hotArticles", hotArticles);
        this.data.put("success", true);

        return SUCCESS;
    }

    public Map<String, Object> getData() {
        return data;
    }

}
